/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cn.mengfly.product.api;


import cn.mengfly.product.entity.Product;
import cn.mengfly.product.entity.ProductComment;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * 商品评论信息DTO定义
 *
 * @author CD826(CD826Dong @ gmail.com)
 * @since 1.0.0
 */
@Data
public class ProductCommentsDto implements Serializable {
    private static final long serialVersionUID = 1L;

    private Product product;
    private int port;

    private List<CommentDto> commentDtoList;


    public ProductCommentsDto() {

    }

    public void addComments(List<CommentDto> commentDtoList) {
        this.commentDtoList = new ArrayList<>();
        this.commentDtoList.addAll(commentDtoList);
    }


    @Data
    public static class CommentDto {
        private Long id;
        private UserDto author;
        private String content;
        private Date created;

        public CommentDto(ProductComment productComment) {
            this.id = productComment.getId();
            this.content = productComment.getContent();
            this.created = productComment.getCreated();
        }

        public CommentDto() {
        }

    }
}